package com.ftg.learn.controller;

import com.ftg.learn.entity.Product;
import com.ftg.learn.service.IProductService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 布衣
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/product")
@Api(tags = "商品管理")
public class ProductController {

    @Resource
    private IProductService productService;
    ;

    @GetMapping("/list")
    @ApiOperation("商品列表")
    public R<String> list(
            @ApiParam(value = "商品名称") @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "页码",required = true) @RequestParam(value = "page") Integer page,
            @ApiParam(value = "显示条数",required = true) @RequestParam(value = "size") Integer size
    ) {
        System.out.println(name+"name");
        return productService.list(name, page, size);
    }

    /**
     * 图片上传功能实现
     *
     * @param product 商品
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加商品")
    public R<Boolean> add(@RequestBody Product product) {
        return R.ok(productService.save(product));
    }

    @PutMapping("/update/{id}")
    @ApiOperation("修改商品")
    public R<String> update(@PathVariable("id") Integer id, @RequestBody Product product) {
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除商品")
    public R<String> delete(@PathVariable("id") Integer id) {
        return R.ok();
    }


}
